﻿Imports System.Data.SqlClient
Public Class Avocat_bureau
    Public Id As Integer
    Public Cin As String
    Public Nom As String
    Public Prenom As String
    Public Nom_a As String
    Public Prenom_a As String
    Public Date_naiss As Date
    Public Date_employement As Date
    Public Ville As String
    Public Situation_social As String
    Public Num_prof As String
    Public Type_avocat As String
    Public Autorite As String
    Public Salaire As Double
    Public Email As String
    Public Adress As String
    Public Photo As Byte()
    Public Remarque As String
    Public Actif As Boolean
    Public type As String
    Public majlissA3la As Boolean

    'Les constructeur -------------------------------

    Sub New(ByVal Id As Integer, ByVal Cin As String, ByVal Nom As String, ByVal Prenom As String, ByVal Nom_a As String, ByVal Prenom_a As String, ByVal Date_naiss As Date, ByVal Date_employement As Date, ByVal Ville As String, ByVal Situation_social As String, ByVal Num_prof As String, ByVal Type_avocat As String, ByVal Autorite As String, ByVal Salaire As String, ByVal Email As String, ByVal Adress As String, ByVal Photo As Byte(), ByVal Remarque As String, ByVal Actif As Boolean, ByVal type As String, ByVal majlissA3la As Boolean)
        Me.Id = Id
        Me.Cin = Cin
        Me.Nom = Nom
        Me.Prenom = Prenom
        Me.Nom_a = Nom_a
        Me.Prenom_a = Prenom_a
        Me.Date_naiss = Date_naiss
        Me.Date_employement = Date_employement
        Me.Ville = Ville
        Me.Situation_social = Situation_social
        Me.Num_prof = Num_prof
        Me.Type_avocat = Type_avocat
        Me.Autorite = Autorite
        If Salaire <> "" Then
            Me.Salaire = CType(Salaire, Double)
        Else
            Me.Salaire = Nothing
        End If
        Me.Email = Email
        Me.Adress = Adress
        Me.Photo = Photo
        Me.Remarque = Remarque
        Me.Actif = Actif
        Me.type = type
        Me.majlissA3la = majlissA3la
    End Sub

    Sub New(ByVal enregistrement As ArrayList)
        Me.Id = enregistrement.Item(0)
        Me.Nom_a = enregistrement.Item(1)
        Me.Prenom_a = enregistrement.Item(2)
        Me.Nom = enregistrement.Item(3)
        Me.Prenom = enregistrement.Item(4)
        Me.Cin = enregistrement.Item(5)
        Me.Date_naiss = enregistrement.Item(6)
        Me.Date_employement = enregistrement.Item(7)
        Me.Ville = enregistrement.Item(8)
        Me.Situation_social = enregistrement.Item(9)
        Me.Num_prof = enregistrement.Item(10)
        Me.Type_avocat = enregistrement.Item(11)
        Me.Autorite = enregistrement.Item(12)
        Me.Salaire = enregistrement.Item(13)
        Me.Email = enregistrement.Item(14)
        Me.Adress = enregistrement.Item(15)
        Me.Remarque = enregistrement.Item(17)
        Me.Actif = enregistrement.Item(16)
        Me.Photo = enregistrement.Item(18)
        Me.type = enregistrement.Item(19)
        Me.majlissA3la = enregistrement.Item(20)
    End Sub

    Sub New()

    End Sub

    'les listes ---------------------------------

    Public list_phone As New ArrayList

    'les fonctions ---------------------------



    Public Sub remplir_List_list_phone()
        Partager.close()
        Me.list_phone.Clear()
        Partager.ad = New SqlDataAdapter("select id,Num,Type from phone where id_Avocat_Bureau=" & Me.Id, Partager.conPhone)
        Partager.ds = New DataSet
        Partager.ad.Fill(Partager.ds, "phone")
        For Each f As DataRow In Partager.ds.Tables(0).Rows
            If f("Num") Is DBNull.Value Then
                f("Num") = ""
            End If
            Dim khab As New Phone(f("id"), f("Num"), f("Type"))
            Me.list_phone.Add(khab)

        Next
        'Partager.Close()
    End Sub

    Public Sub suprimmer_phone(ByVal id As Integer, ByVal type As String)

        Dim cmd As New SqlClient.SqlCommand("delete from phone where Type='" & type & "' And Id_Avocat_Bureau=" & id, Partager.con)

        Partager.Open()
        cmd.ExecuteNonQuery()
        Partager.Close()

        'Me.remplir_List_list_phone()


    End Sub

    Public Sub Ajouter_phone(ByVal ph As Phone)

        Dim cmd As New SqlClient.SqlCommand("insert into phone(Num,Type,Id_Avocat_Bureau) values (@Num,@Type,@Id_Avocat_Bureau)", Partager.con)
        'ici'
        cmd.Parameters.Add("@Id_Avocat_Bureau", SqlDbType.Int).Value = Me.Id
        cmd.Parameters.Add("@Type", SqlDbType.VarChar).Value = ph.Type
        cmd.Parameters.Add("@Num", SqlDbType.VarChar).Value = ph.Num


        Partager.Open()
        cmd.ExecuteNonQuery()
        Partager.Close()

        ' Me.remplir_List_list_phone()


    End Sub

    'Public Sub modifier_List_phone(ByVal idd As Integer, ByVal ph As Phone)



    '    Dim cmd As New SqlClient.SqlCommand("update phone set  Num=@Num where id" & Id, Partager.con)


    '    cmd.Parameters.Add("@Num", SqlDbType.VarChar).Value = ph.Num

    '    Partager.Open()
    '    cmd.ExecuteNonQuery()
    '    Partager.Close()

    '    Me.remplir_List_list_phone()

    'End Sub

End Class
